var app = getApp()
Page({
  data: {
    arraydetail: [],
    author: 'Lotus'
  },
  del: function (e) {
    console.log('112233445566');
  
    var that = this;
    var addressId = e.currentTarget.id;
    var openidinfo = app.globalData.openId;
    app.util.request({
      method: 'POST',
      url: 'entry/wxapp/deladdress',
      data: { openid: openidinfo, id: addressId },
      header: { 'Content-Type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        console.log(res);
        that.getlist();
      },
      fail: function (res) {
        //console.log("fail:" + res);
      },
    })
  },
  setDefault: function (e) {
    var that = this;
    var service = 'ReceiptAddress.setDefault';
    var addressId = e.target.dataset.id;
    wx.request({
      method: 'POST',
      url: app.globalData.APIURL,
      data: { service: service, openId: app.globalData.openId, addressId: addressId },
      header: { 'Content-Type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        //console.log("success:" + res.data.data);      
        wx.switchTab({
          url: 'mycart'
        })
      },
      fail: function (res) {
        //console.log("fail:" + res);
      },
    })
  },
  getlist: function () {
    var that = this;
    var openidinfo = app.globalData.openId;
    app.util.request({
      'url': 'entry/wxapp/getaddresslist&openid=' + openidinfo,
      'cachetime': '30',
      success: function (res) {
        console.log(res.data.data);
        var addressinfo = res.data.data;
        that.setData({
          arraydetail: addressinfo,
        })
      }
    })
  },
  onLoad: function (options) {
    var that = this;
    if (options.fromInviteCode) {
      app.globalData.fromInviteCode = options.fromInviteCode;
    }
    app.appstart();
    that.getlist();
  }
})